package com.yi.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2 接口测试框架
 * @author YI
 * @date 2018-3-19 16:17:59
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    /**
     * 集成swagger2，服务器启动后可以访问如下地址查看接口
     * http://localhost:9000/swagger-ui.html
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yi.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("项目请关注：https://github.com/HWYWL/spring-boot")
                .contact(new Contact("YI", "http://www.hwy.ac.cn", "ilovey_hwy@163.com"))
                .version("1.0")
                .build();
    }

}